/**
 * partnerSoapSforceComWrapper recreates the operation methods
 * generated in the partnerSoapSforceCom class using parameters and
 * return values based on native Salesforce types.
 *
 * @author  Marty Y. Chang
 * @version alpha
 */
public class partnerSoapSforceComWrapper {
    
    private static partnerSoapSforceCom.Soap stub;
    
    private static void configuraStub(String username, String password)
    {
        /*
         * Create a stub instance of the portType that will be used to
         * carryout the desired operation.
         */
        stub = new partnerSoapSforceCom.Soap();
        
        /*
         * Authenticate with the web service by logging into the
         * target Salesforce org.
         */
        partnerSoapSforceCom.LoginResult loginResult =stub.login(username, password);
        
        /*
         * Update the endpoint to reflect the actual org in which the
         * deletion will be carried out.
         */
        stub.endpoint_x = loginResult.serverUrl;
        
        /*
         * Update the stub to operate within the context of the newly
         * established session by setting the <code>sessionId</code>
         * value in the stub.
         */
        stub.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
        stub.SessionHeader.sessionId = loginResult.sessionId;
    }
    
    /**
     * Delete records based on a list of specified salesforce.com Ids.
     * A username and a password are provided to determine the org
     * from which the records will be deleted.
     *
     * @param  ids      the list of salesforce.com Ids of records to delete
     * @param  username the username for the user that will be used to
     *                  perform the delete operation
     * @param  password the password (including the security token)
     *                  associated with <code>username</code>
     * @return          true on successful deletion; false on failure
     */
    public static Boolean delete_x(String[] ids, String username, String password) {
        
        /*
         * Define the return value.  Assume failure until success is attained.
         */
        Boolean success = false;
        
        configuraStub(username, password);
        
        /*
         * Perform the actual deletion by calling the method that was
         * automatically generated from the Partner WSDL.
         */
        partnerSoapSforceCom.DeleteResult[] deleteResults =stub.delete_x(ids);
        
        /*
         * Assume that if no exceptions were encountered that the deletion
         * was successful.
         */
        success = true;
        
        return success;
    }
    
    
    public static Boolean upsert_x( String username, String password) {
    
        
        Boolean success = false;
        
        List<sobjectPartnerSoapSforceCom.sObject_x> sObjects = new List<sobjectPartnerSoapSforceCom.sObject_x>();           
        sobjectPartnerSoapSforceCom.sObject_x tmpObj = new sobjectPartnerSoapSforceCom.sObject_x();
        
            tmpObj.type_x = 'Account';
            tmpObj.AcctName = 'Cuenta de Blanca';    
            tmpObj.ExtID= 'Cuenta de Blanca';
            tmpObj.AcctDesc= '-Creada por WS';        
            sObjects.add(tmpObj);
    
        configuraStub(username, password);
        
        partnerSoapSforceCom.UpsertResult[] updateResults = stub.upsert_x('External_ID__c',sObjects);
        
        success = true;
        
        return success;
    }
    
    public static Boolean update_x( String username, String password) {
    
        
        /*
         * Define the return value.  Assume failure until success is attained.
         */
        Boolean success = false;
        
        List<sobjectPartnerSoapSforceCom.sObject_x> sObjects = new List<sobjectPartnerSoapSforceCom.sObject_x>();           
        sobjectPartnerSoapSforceCom.sObject_x tmpObj = new sobjectPartnerSoapSforceCom.sObject_x();


            tmpObj.type_x = 'Account';
            tmpObj.Id = '001U0000009MsYe';//ID de la cuenta en el entorno de Diego
            tmpObj.AcctName = 'sadfasdfasdf';//Nombre de la cuenta en el entorno de Diego
            tmpObj.ExtID= 'sadfasdfasdf';//ExternalID de la cuenta en el entorno de Diego
            tmpObj.AcctDesc= '-Modificado por WS';             
       
            sObjects.add(tmpObj);
    
        configuraStub(username, password);
        
        partnerSoapSforceCom.SaveResult[] updateResults = stub.update_x(sObjects);
        
        /*
         * Assume that if no exceptions were encountered that the deletion
         * was successful.
         */
        success = true;
        
        return success;
    }

}